class Query {
    static queryByPnt({
        position,
        service,
        success
    }) {
        //1、初始化查询结构对象，设置查询结构包含几何信息
        var queryStruct = new Zondy.Service.QueryFeatureStruct();
        //是否包含几何图形信息
        queryStruct.IncludeGeometry = true;
        //是否包含属性信息
        queryStruct.IncludeAttribute = true;
        //是否包含图形显示参数  默认值就是false
        // queryStruct.IncludeWebGraphic = false;
        /* 2、设置查询规则 */
        var rule = new Zondy.Service.QueryFeatureRule({
            //是否将要素的可见性计算在内
            EnableDisplayCondition: false,
            //是否完全包含
            MustInside: false,
            //是否仅比较要素的外包矩形
            CompareRectOnly: false,
            //是否相交
            Intersect: true
        });
        //3、实例化查询参数对象
        //创建一个用于查询的点形状
        let pointObj = new Zondy.Object.Point2D(position[0], position[1]);
        //设置查询点的搜索半径
        pointObj.nearDis = 0.001;
        var queryParam = new Zondy.Service.QueryParameter({
            geometry: pointObj,
            resultFormat: "json",
            struct: queryStruct,
            rule: rule
        });
        //4、实例化地图文档查询服务对象
        var queryService = new Zondy.Service.QueryDocFeature(queryParam, service.name, service.layerId, {

        });
        //执行查询操作，querySuccess为查询回调函数
        queryService.query(this.onSuccess(success));
    }
    static queryByGeom({
        geometry,
        service,
        success
    }) {
        /* 1、设置要素的查询构建 geoemetry,style,attr */
        var queryStruct = new Zondy.Service.QueryFeatureStruct();
        //是否包含几何图形信息
        queryStruct.IncludeGeometry = true;
        //是否包含属性信息
        queryStruct.IncludeAttribute = true;
        //是否包含图形显示参数
        queryStruct.IncludeWebGraphic = false;
        /* 2、设置查询的规则 */
        //指定查询规则
        var rule = new Zondy.Service.QueryFeatureRule({
            //是否将要素的可见性计算在内
            EnableDisplayCondition: false,
            //是否完全包含
            MustInside: false,
            //是否仅比较要素的外包矩形
            CompareRectOnly: false,
            //是否相交
            Intersect: true
        });
        /* 3、设置查询参数 */
        //实例化查询参数对象
        var geomObj = new Zondy.Object.Polygon();
        //feature.getGeometry()
        geomObj.setByOL(geometry);
        var queryParam = new Zondy.Service.QueryParameter({
            geometry: geomObj,
            resultFormat: "json",
            struct: queryStruct,
            rule: rule
        });
        //设置查询分页号
        queryParam.pageIndex = 0;
        //设置查询要素数目
        queryParam.recordNumber = 100;
        var queryService = new Zondy.Service.QueryDocFeature(queryParam, service.name, service.layerId, {

        });
        //执行查询操作，querySuccess为查询回调函数
        queryService.query(this.onSuccess(success));
    }
    static queryByLayerId({
        service,
        success
    }) {
        //1、初始化查询结构对象，设置查询结构包含几何信息
        var queryStruct = new Zondy.Service.QueryFeatureStruct();
        //是否包含几何图形信息
        queryStruct.IncludeGeometry = true;
        //是否包含属性信息
        queryStruct.IncludeAttribute = true;
        //是否包含图形显示参数
        queryStruct.IncludeWebGraphic = false;
        //2、指定查询规则
        var rule = new Zondy.Service.QueryFeatureRule({
            //是否将要素的可见性计算在内
            EnableDisplayCondition: false,
            //是否完全包含
            MustInside: false,
            //是否仅比较要素的外包矩形
            CompareRectOnly: false,
            //是否相交
            Intersect: true
        });
        //3、实例化查询参数对象
        var queryParam = new Zondy.Service.QueryParameter({
            resultFormat: "json",
            struct: queryStruct,
            rule: rule
        });
        //设置查询分页号
        queryParam.pageIndex = 0;
        //设置查询要素数目
        queryParam.recordNumber = 100;
        //实例化地图文档查询服务对象
        var queryService = new Zondy.Service.QueryDocFeature(queryParam, service.name, service.layerId, {

        });

    //执行查询操作，querySuccess为查询回调函数
    queryService.query(this.onSuccess(success))
  }
  /**
   * 
   * @param {*} keyword 查询关键字
   * @param {*} type 查询类型，common-普通查询，admin/traffic-交管查询
   */
  static queryByAttr({ service, keyword, type, success }) {
    var queryStruct = new Zondy.Service.QueryFeatureStruct()
    //是否包含几何图形信息
    queryStruct.IncludeGeometry = true
    //是否包含属性信息
    queryStruct.IncludeAttribute = true
    //是否包含图形显示参数
    queryStruct.IncludeWebGraphic = false
    //实例化查询参数对象
    var queryParam = new Zondy.Service.QueryParameter({
      resultFormat: 'json',
      struct: queryStruct
    })
    //设置查询分页号
    queryParam.pageIndex = 0

    //设置查询要素数目
    queryParam.recordNumber = 1000
    //设置查询条件
    // var condition
    // if (type == 'common') {
    //   condition =
    //     "处理状态 != 2 AND (事件类型 LIKE '%" + keyword + "%' OR 发生地点 LIKE '%" + keyword + "%')"
    // } else {
    //   condition = "发生地点 LIKE '%" + keyword + "%' OR 事件类型 LIKE '%" + keyword + "%'"
    // }
    // console.log(condition)
    if (type.value == 'common') {
      queryParam.where = "处理状态 !=2 AND ("+keyword+")"
    }else{
      queryParam.where = keyword
    }
    var queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.name,
      service.layerId,
      {}
    )
    //执行查询操作，querySuccess为查询回调函数
    queryService.query(this.onSuccess(success))
  }
  static onSuccess(success) {
    return function (data) {
      /* data -mapgis-json */
      var format = new Zondy.Format.PolygonJSON()
      //将MapGIS要素JSON反序列化为ol.Feature类型数组
      var features = format.read(data)
      success(features)
    }
  }
}

export { Query }
